#include "interface.h"
#include <caml/callback.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>

int main(int	argc,
	 char	**argv)
{
  SDL_Surface *screen = NULL, *background_picture = NULL;
  SDL_Rect background_position;

  if (argc == 2)
  {
    caml_startup(argv);
    String_val(caml_callback(*caml_named_value("key_generate"),caml_copy_string("text")));
  }
  else
  {
  caml_startup(argv);
  background_position.x = 0;
  background_position.y = 0;
  SDL_Init(SDL_INIT_VIDEO);
  SDL_EnableKeyRepeat(500, 5);
    screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE); /* open a window  */
  SDL_WM_SetCaption("Steganodio", NULL);
  background_picture = IMG_Load("fondecr.png");
  if (background_picture == NULL)
  {
    printf("Fatal error! background picture not found");
    SDL_Quit();
    return (-42);
  }
  SDL_BlitSurface(background_picture, NULL, screen, &background_position); /* open of the picture  */
  interface_write(NULL, NULL,NULL, background_picture, screen, NULL);/* update of the screen with a new color */
  SDL_Flip(screen);
  event2(screen,background_picture);
/* free the surface */
  SDL_FreeSurface(background_picture);
  SDL_Quit();
  }
  return(EXIT_SUCCESS);
}
